package com.isotronica.neveras.datos.conn;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ConnectionDB {

	private static Connection conn = null;
	private static String url = "jdbc:mysql://190.9.73.61:3306/";
	private static String db = "medex_neveras";
	private static String driver = "com.mysql.jdbc.Driver";
	private static String user = "isotronica";
	private static String pass = "1s0tr0n1c4";

	public ConnectionDB() {
	
	}

	public static Connection getConnectionDB() {

		if (conn == null)
			conectar();
		try {
			if (conn != null)
				if (conn.isClosed()) {
					conn = null;
					conectar();
				}

		} catch (SQLException e) {
			System.out.println("Re conected");
		}

		return conn;
	}

	public static Connection conectar() {
		try {
			Class.forName(driver);
		} catch (ClassNotFoundException e) {
			conn = null;
			System.out.println("Driver");
		}

		try {
			conn = DriverManager.getConnection(url + db, user, pass);
		} catch (SQLException e) {
			conn = null;
			System.out.println("Conexion Fallo");
		}

		return conn;

	}

	public boolean close() {
		try {
			conn.close();
			conn = null;
			return true;
		} catch (SQLException e) {
			e.printStackTrace();
			return false;
		}
	}
}
